import * as echarts from 'echarts';

export default {
    setOption: (xData, yData, xName = '', yName = '', title) => {

        return {
            //提示框组件
            tooltip: {
                trigger: 'axis',
                position: function (pt) {
                    return [pt[0], '10%'];
                }
            },
            //标题
            title: {
                left: 'center',
                text: title
            },
            //工具盒
            toolbox: {
                orient: 'vertical',
                feature: {
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    dataView: { readOnly: false },
                    magicType: { type: ['line', 'bar'] },
                    restore: {},
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                name: xName,
                boundaryGap: false,
                data: xData
            },
            yAxis: {
                type: 'value',
                name: yName,
                boundaryGap: [0, '100%']
            },
            grid: {
                bottom: 80
            },
            //区域的缩放
            dataZoom: [{
                type: 'inside',
                start: 0,
                end: 10
            }, {
                start: 0,
                end: 10,
                handleSize: '100%',
                handleStyle: {
                    color: 'rgba(47, 201, 225, 1)',
                    shadowBlur: 3,
                    shadowColor: 'rgba(0, 0, 0, 0.6)',
                    shadowOffsetX: 2,
                    shadowOffsetY: 2
                }
            }],
            series: [
                {
                    name: '电压',
                    type: 'line',
                    smooth: true,
                    symbol: 'none',
                    sampling: 'average',
                    itemStyle: {
                        color: 'rgb(255, 70, 131)'
                    },
                    areaStyle: {
                        color: echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgb(255, 158, 68)'
                        }, {
                            offset: 1,
                            color: 'rgb(255, 70, 131)'
                        }])
                    },
                    data: yData
                }
            ]
        };
    }
};
